package ar.com.unlp.fi.lrs.domain;

import java.util.Date;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Transient;

import com.fasterxml.jackson.annotation.JsonTypeName;

/**
 * 
 * https://github.com/adlnet/xAPI-Spec/blob/master/xAPI.md#stmtprops
 * 
 */

@Entity
@Table(name = "Statement")
@DiscriminatorValue(value = "STATEMENT")
@JsonTypeName("STATEMENT")
public class Statement implements StatementObject {

	private long id = 0;

	private Actor actor;

	private Verb verb;

	// Puede ser una actividad, un actor (tipo agente) u otro statement
	private StatementObject object;

	private long objectId; //EL id para recuperar el object

	private String objectType; // El tipo del object

	private Result result;

	private Context context= new Context();

	private Date timestamp;

	private Date stored;

	private Actor authority;

	private Attachment attachment;

	@Id
	@GeneratedValue
	@Column(name = "ID")
	public long getId() {
		return id;
	}

	public void setId(long id) {
		this.id = id;
	}

	@ManyToOne
	@JoinColumn(name = "ACTOR_ID", nullable = false)
	public Actor getActor() {
		return actor;
	}

	public void setActor(Actor actor) {
		this.actor = actor;
	}

	@ManyToOne
	@JoinColumn(name = "VERB_ID", nullable = false)
	public Verb getVerb() {
		return verb;
	}

	public void setVerb(Verb verb) {
		this.verb = verb;
	}


	@Transient
	public StatementObject getObject() {
		return object;
	}

	public void setObject(StatementObject object) {
		this.object = object;
	}

	@Transient
	public Result getResult() {
		return result;
	}

	public void setResult(Result result) {
		this.result = result;
	}
	
//	@OneToOne(cascade=CascadeType.ALL )
//	@JoinColumn(name = "ATTACHMENT_ID", nullable = true)
//	public Attachment getAttachment() {
//		return attachment;
//	}
//
//	public void setAttachment(Attachment attachment) {
//		this.attachment = attachment;
//	}


	@OneToOne(cascade=CascadeType.ALL)
	@JoinColumn(name = "CONTEXT_ID", nullable = true)
	public Context getContext() {
		return context;
	}

	public void setContext(Context context) {
		this.context = context;
	}

	@Column(name = "TIMESTAMP")
	public Date getTimestamp() {
		return timestamp;
	}

	public void setTimestamp(Date timestamp) {
		this.timestamp = timestamp;
	}

	@Column(name = "STORED")
	public Date getStored() {
		return stored;
	}

	public void setStored(Date stored) {
		this.stored = stored;
	}

	@ManyToOne
	@JoinColumn(name = "AUTHOR_ID")
	// @Transient
	public Actor getAuthority() {
		return authority;
	}

	public void setAuthority(Actor authority) {
		this.authority = authority;
	}



	@Column(name = "OBJECTTYPE")
	public String getObjectType() {
		return objectType;
	}

	public void setObjectType(String objectType) {
		this.objectType = objectType;
	}

	@Column(name = "OBJECT_ID")
	public long getObjectId() {
		return objectId;
	}

	public void setObjectId(long objectId) {
		this.objectId = objectId;
	}

	@Override
	@Transient
	public String getObjectStatemetnType() {
		return StatementObject.STATEMENT;
	}

}
